package com.vpx.server.controller.system;

import com.vpx.server.bean.order.base.BaseDeleteOrder;
import com.vpx.server.bean.order.base.BaseIdOrder;
import com.vpx.server.bean.order.system.SysRoleAuthOrder;
import com.vpx.server.bean.order.system.SysRoleOrder;
import com.vpx.server.bean.order.system.SysRolePageOrder;
import com.vpx.server.framework.authority.AuthPoicy;
import com.vpx.server.framework.authority.RequestAuth;
import com.vpx.server.bean.result.system.SysRoleResult;
import com.vpx.server.framework.base.ResultMsg;
import com.vpx.server.service.system.SysRoleService;
import com.vpx.server.bean.result.base.BaseDeleteResult;
import com.vpx.server.bean.result.system.SysRoleMenuOperateAuthResult;
import com.vpx.server.bean.result.system.SysRolePageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liuks
 * @title: vpx
 * @module 角色管理
 * @description: 角色管理接口
 * @date 2021/9/9
 */
@RestController
@RequestMapping(value = "/api/role")
@Api(tags = "基础设置-角色管理")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @PostMapping("insert")
    @ApiOperation("新增角色")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg insert(@RequestBody SysRoleOrder order) {
       return sysRoleService.insert(order);
    }

    @DeleteMapping("deleteById")
    @ApiOperation("删除角色")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg deleteById(@RequestBody BaseDeleteOrder order) {
        return sysRoleService.deleteById(order);
    }

    @PutMapping("updateById")
    @ApiOperation("修改角色")
    public ResultMsg updateById(@RequestBody SysRoleOrder order) {
        return sysRoleService.updateById(order);
    }

    @GetMapping("findById")
    @ApiOperation("查询角色")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg<SysRoleResult> findById(BaseIdOrder order) {
        return sysRoleService.findById(order);
    }

    @GetMapping("pageQuery")
    @ApiOperation("分页查询角色列表")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg<SysRolePageResult> pageQuer(SysRolePageOrder order) {
        return sysRoleService.pageQuery(order);
    }

    @GetMapping("findRoleAuthById")
    @ApiOperation("查询角色菜单操作权限")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg<SysRoleMenuOperateAuthResult> findRoleAuthById(BaseIdOrder order) {
        return sysRoleService.findRoleMenuOperateAuth(order);
    }

    @PostMapping("saveRoleAuth")
    @ApiOperation("保存角色权限")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg saveRoleAuth(@RequestBody SysRoleAuthOrder order) {
        return sysRoleService.saveRoleAuth(order);
    }

}
